<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
			<button @click="select()">查询</button>
			<button @click="insert()">添加</button>
			<button @click="update()">修改</button>
			<button @click="execute()">修改</button>
			<button @click="getItem()">查单一</button>
		</view>
		<view class="">
			{{ Test.list }}
			{{ Test.loading }}
			{{ Test.state }}
		</view>
		<view class="">
			<button @click="test()">请求odoo版本</button>
			<button @click="re()">带登陆</button>
			<button @click="tttt()">odoo_api</button>
			<button @click="logout()">注销</button>
		</view>
	</view>
</template>

<script>
	import {
		HandleSQLite
	} from '@/utils/handle_SQLite.js'
	import {
		localSqliteApi
	} from '@/api/local_sqlite_api.js'
	import {odooLogin,odooBaseApi,odooLogout} from '@/api/odoo_api.js'

	// 使用odoojs调用odoo接口
	import api from '@/utils/odoorpc'

	export default {
		data() {
			return {
				title: 'Hello',
				Test: new HandleSQLite(localSqliteApi, 'main', 'table1'),
				custom_list: [],
				offset: 1
			}
		},
		onLoad() {

		},
		methods: {
			logout(){
				odooLogout()
			},
			async tttt(){
				await odooLogin('admin','123').then(res=>{
					console.log(res)
				})
				await odooBaseApi().getList()
			},
			test() {
				// const request = new XMLHttpRequest()
				// const url = "http://127.0.0.1:8069/web/webclient/version_info"
				// request.open("POST",url,true)
				// request.setRequestHeader('Content-type','application/json')
				// request.send()

				// uni.request({
				// 	url: 'http://192.168.2.128:8069/web/session/authenticate',
				// 	method: "POST",
				// 	data: {
				// 		params: {
				// 	db: 'odoo15',
				// 	login: 'admin@admin.com',
				// 	password: '123456',
				// },
				// 		jsonrpc: '2.0',
				// 		method: 'call',
				// 		id: Math.floor(Math.random() * 100000000 + 1)
				// 	},
				// 	success: (res) => {
				// 		console.log(res);
				// 	}

				// })

				// uni.request({

				// 	url: 'http://192.168.2.128:8069/web/session/authenticate',
				// 	method: "POST",
				// 	data: {
				// 		params: {
				// 	db: 'odoo15',
				// 	login: 'admin@admin.com',
				// 	password: '123456',
				// },
				// 		jsonrpc: '2.0',
				// 		method: 'call',
				// 		id: Math.floor(Math.random() * 100000000 + 1)
				// 	},
				// 	success: (res) => {
				// 		console.log(res);
				// 	}

				// })
				uni.request({
					url: 'http://47.254.174.245:8013/web/dataset/call_kw/spedition.sheet/search_read',
					method: "POST",
					data: {
						"jsonrpc": "2.0",
						"method": "call",
						"params": {
							"model": "ir.module.module",
							"method": "search_read",
							"args": [],
						
							"kwargs": {
								"domain": [],
								"fields": [],
								"limit": 2,
								"offset": 1,
								"order": "name",
								"context": {
									"lang": "zh_CN",
									"tz": "Asia/Shanghai",
									"uid": 2,
									"allowed_company_ids": [1]
								}
							}
						},
						"id": Math.floor(Math.random() * 1000000000 + 1)
					},
					success: (res) => {
						console.log(res);
					}

				})
			},
			async re() {
				// let res = await api.web.database.list({}) // 查看有哪些数据库
				// // // let res = api.web.login({
				// // // 	db:'odoo15',
				// // // 	login:'admin@admin.com',
				// // // 	password:'123456',
				// // // }) // 查看有哪些数据库
				await api.web.session.authenticate({
					db: 'WMS_en',
					login: 'admin',
					password: '123',
					// login: 'yang',
					// password: '123',
				})
				// // await api.web.session.authenticate({
				// // 	db:'WMS_de',
				// // 	login:'yang',
				// // 	password:'123',
				// // })
				// let Model = await api.env.model('ir.module.module')
				let Model = await api.env.model('container.status')
				let context = await Model.search_read({
					domain: [['id','=','9']],
					fields: [],
					limit: 20,
					offset: this.offset,
					order: 'name'
				})
				// Model.execute_kw()
				// context = Model.env.context
				// api.web.dataset.call_kw()
				// console.log(res)
				console.log(Model)
				// console.log("123")
			},
			select() {
				this.Test.getList()
			},
			insert() {
				this.Test.execute("insert", {
					"test": 'tttt'
				})
			},
			update() {
				this.Test.execute('update', {
					id: 1,
					context: {
						test: '已经上架123',
					}
				})
			},
			execute() {
				this.Test.execute('getList', {
					"id": 12
				})
			},
			getItem() {
				this.Test.execute('getItem', 1)
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
